﻿using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UFSoft.UBF.UI.ControlModel;
using UFSoft.UBF.UI.Engine.Builder;
using UFSoft.UBF.UI.WebControlAdapter;

namespace MF_HSD_UIPlug
{
    public partial class HSDStdUnitCostUIFormWebPart : UFSoft.UBF.UI.Custom.ExtendedPartBase
    {

        public override void AfterInit(UFSoft.UBF.UI.IView.IPart part, EventArgs args)
        {
            this.Do_AfterInit(part, args); ;
        }
        #region 字段与属性                                       
        private UFIDA.U9.COST.CA.StdUnitCostUIModel.StdUnitCostUIFormWebPart _strongPart;
        IUFButton BtnCreateStdUnitCost = new UFWebButtonAdapter();
        #endregion
        private void Do_AfterInit(UFSoft.UBF.UI.IView.IPart part, EventArgs args)
        {
            #region 获取相关强类型数据                               

            _strongPart = part as UFIDA.U9.COST.CA.StdUnitCostUIModel.StdUnitCostUIFormWebPart;
            if (_strongPart == null)
                return;
            //（2）、加入功能栏Card中
            IUFToolbar toolbar = (IUFToolbar)part.GetUFControlByName(part.TopLevelContainer, "Toolbar2");
            if (toolbar != null)
            {
                string guid = "047FC9F5-46C0-449A-83C2-2822BCF24012";
                BtnCreateStdUnitCost = UIControlBuilder.BuilderToolbarButton(toolbar, "True", " BtnCreateStdUnitCost", "True", "True", 80, 28, "7", "", true, false, guid, guid, guid);
                UIControlBuilder.SetButtonAccessKey(BtnCreateStdUnitCost);
                BtnCreateStdUnitCost.Text = "指定定额成本";
                BtnCreateStdUnitCost.ID = " BtnCreateStdUnitCost";
                BtnCreateStdUnitCost.AutoPostBack = true;
                BtnCreateStdUnitCost.UIModel = part.Model.ElementID;
                ((UFWebToolbarAdapter)toolbar).Items.Add(BtnCreateStdUnitCost as System.Web.UI.WebControls.WebControl);
                BtnCreateStdUnitCost.Click += new EventHandler(BtnCreateStdUnitCost_Click);
            }
            #endregion

        }

        public void BtnCreateStdUnitCost_Click(object sender, EventArgs e)
        {
            try
            {
                _strongPart.IsDataBinding = true;
                _strongPart.IsConsuming = false;
                _strongPart.DataBind();
                _strongPart.DataCollect();
                _strongPart.OnDataCollect(this);
                _strongPart.Model.ClearErrorMessage();          
                string formID = string.Empty;
                NameValueCollection param = new NameValueCollection();
                formID = "e02a09c8-e0c2-4815-8193-79798ba2849a";
                _strongPart.ShowModalDialog(formID, "指定定额成本 ", "320", "208", string.Empty, param, false);
            }
            catch (Exception ex)
            {
                _strongPart.Model.ErrorMessage.Message = ex.Message;
            }
        }
    }
}
